<?php
require_once 'classquantritin.php';
$qt = new quantritin();
$pageNum = 1;
if (isset($_GET['pageNum']))
    $pageNum = $_GET['pageNum'];
$pageSize = 10;
$working = $qt->list_working($pageNum, $pageSize);
$totalRow = $qt->totalTable('working');
?>
<script>
    $(document).ready(function() {
        $("a[title='inactive']").click(function() {
            var id = $(this).attr("id");
            var obj = this;
            //$(this).removeClass("inactive").addClass("active"); 
            $.ajax({
                url: 'working_status.php',
                data: 'id=' + id,
                cache: false,
                success: function(data) {
                    var ob = $(obj).children();
                    data = $.trim(data);
                    if (data == "active") {
                        ob.removeClass("inactive").addClass("active");
                    }
                    if (data == "inactive") {
                        ob.removeClass("active").addClass("inactive");
                    }
                }
            });
        });

        $("a[title='Delete']").click(function() {
            var f = confirm("Bạn muốn xóa?");
            if (f == 1) {
                id = $(this).attr("id");
                $.ajax({
                    url: 'del_row.php',
                    data: 'id=' + id,
                    cache: false,
                    success: function(data) {
                        window.location.reload(true);
                    }
                });
            }
        });
    });
</script>
<div class="well heading">
    <div class="pull-left">
        <h1><span class="glyphicon glyphicon-list-alt"></span> Danh sách lịch công tác</h1>
    </div>
    <div class="pull-right"><a href="index.php?p=working_add" class="btn btn-primary btn-stan-sm"> <span class="glyphicon glyphicon-plus"></span> <span class="text">Thêm</span></a></div>
</div>
<table class="table table-bordered">
    <thead>
        <tr>
            <td width="1" class="text-center"><input type="checkbox" id="check_all" name="check_all"></td>
            <td>Nội dung</td>
            <td>Địa điểm</td>
            <td>Nhân sự</td>
            <td>Đi</td>
            <td>Về</td>
            <td>Action</td>
            <td>ID</td>
        </tr>
    </thead>
    <tbody>
        <?php
        while ($row_working = mysql_fetch_assoc($working)) {
            $status = $row_working['status'] == 0 ? "active" : "inactive";
            ?>
    <?php ob_start() ?>
            <tr>
                <td><input type="checkbox" value="69" name="selected[]"></td>
                <td><a href="index.php?p=working_edit&id=<?php echo $row_working['id'] ?>">{content}</a></td>
                <td>{address}</td>
                <td>{emp}</td>
                <td>{checkout}</td>
                <td>{checkin}</td>
                <td>
                    <a title="inactive" href="#" class="btn btn-icon" id=<?php echo $row_working['id'] ?>><i class="glyphicon glyphicon-ok-sign <?php echo $status ?>" ></i></a> 
                    <a title="Edit" class="btn btn-icon" href="index.php?p=working_edit&id=<?php echo $row_working['id'] ?>">
                        <i class="glyphicon glyphicon-file"></i>
                    </a> 
                    <a title="Delete" class="btn btn-icon" id=<?php echo $row_working['id'] ?>>
                        <i class="glyphicon glyphicon-trash" ></i>
                    </a>
                </td>
                <td><?php echo $row_working['id'] ?></td>
            </tr>  
            <?php
            $str = ob_get_clean();
            $str = str_replace("{content}", $row_working['content'], $str);
            $str = str_replace("{address}", $row_working['address'], $str);
            $str = str_replace("{emp}", $row_working['emp'], $str);
            $str = str_replace("{checkout}", date('d/m/Y H:i', strtotime($row_working['checkout'])), $str);
            if($row_working['checkin'] == '0000-00-00 00:00:00') $checkin = "";
            else $checkin = date('d/m/Y H:i', strtotime($row_working['checkin']));
            $str = str_replace("{checkin}",$checkin , $str);
            $str = str_replace("{feature}", $row_working['status'] == 1 ? "inactive" : "active", $str);
            echo $str;
            ?>
        <?php }
        ?>
    </tbody>
</table>
<ul class="pagination pull-right">
<?php echo $qt->pagesList($totalRow, $pageNum, $pageSize) ?>
</ul>

